package com.mapbased.cc.form;

import java.io.*;

import org.dom4j.*;
import com.mapbased.wfw.*;
import com.mapbased.wfw.PageLoader.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: mapbased.com</p>
 *
 * @author chy_hs(Baily)
 * @version 1.0
 */
public class CheckboxFormElement
    extends FormElement
{
    private String value="";

    final public void renderInputPart(RenderContext rc)
        throws IOException
    {
        java.io.Writer w=rc.getOutputWriter();
        w.write("<input class=\"");
        w.write(this.css == null ? this.getType() : this.css);

        w.write("\" type=\"");
        w.write(this.getType());

        if(this.style != null)
        {
            w.write("\" style=\"");
            w.write(this.style);

        }

        w.write("\" id=\"");

        w.write(this.name);

        w.write("\" name=\"");

        w.write(this.name);

        w.write("\" value=\"");

        w.write(this.value);
        w.write("\" ");
        if(this.value.equals(rc.getSureSingleParam(this.name)))
        {
            w.write("checked=\"checked\" ");
        }
        if(this.events!=null)
        {
            w.write(this.events);
        }

        w.write("/>");

    }

    final protected String getType()
    {
        return "checkbox";
    }

    /**
     * initCustom
     *
     * @param e Element
     * @param pl LoadContext
     * @todo Implement this com.mapbased.cc.form.FormElement method
     */
    protected void initCustom(Element e,LoadContext pl)
    {
        this.value=e.attributeValue("value","");
    }

    public void setValue(String value)
    {
        this.value=value;
    }

    public String getValue()
    {
        return value;
    }

}
